package org.linlinjava.litemall.admin.util;

import com.github.pagehelper.Page;

import java.io.Serializable;
import java.util.List;

/**
 * @Description: TODO
 * @author: Destin
 * @date: 2021-10-09
 */
public class PageResults<T> implements Serializable {
    private long totalElements;
    private List<T> list;
    private int limit;
    private int pages;
    private int total;
    private int numberOfElements;

    public PageResults() {
    }

    public PageResults(List<T> list) {
        if (list instanceof Page) {
            Page<T> page = (Page)list;
            this.limit = page.getPageNum();
            this.pages = page.getPageSize();
            this.totalElements = page.getTotal();
            this.total = page.getPages();
            this.list = page.getResult();
            this.numberOfElements = page.size();
        } else {
            this.list = list;
        }

    }

    public long getTotalElements() {
        return this.totalElements;
    }

    public void setTotalElements(long totalElements) {
        this.totalElements = totalElements;
    }

    public List<T> getList() {
        return this.list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getLimit() {
        return this.limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public int getPages() {
        return this.pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public int getTotal() {
        return this.total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getNumberOfElements() {
        return this.numberOfElements;
    }

    public void setNumberOfElements(int numberOfElements) {
        this.numberOfElements = numberOfElements;
    }

    public static <T> PageResults<T> build(List<T> list) {
        return new PageResults(list);
    }
}
